package com.ftg.learn.bus.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.learn.bus.entity.BusInfo;
import com.ftg.learn.bus.service.IBusInfoService;
import com.ftg.learn.util.ResEntity;
import com.ftg.learn.util.ResPageEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 公车信息表 前端控制器
 * </p>
 *
 * @author lalala
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/bus/bus-info")
@Api(tags = "公车信息管理功能列表")
public class BusInfoController extends CrudpController<BusInfo, IBusInfoService> {

    @GetMapping("/showBusInfoDirector")
    @ApiOperation(value = "查询所有车的信息及其负责人信息(真)")
    public ResEntity showBusInfoDirector(){
        return new ResEntity(0,"success",super.service.showBusInfoDirector());
    }

    @GetMapping("/showDirectorForBid")
    @ApiOperation(value = "根据车的信息查询负责人信息(真)")
    public ResEntity showDirectorForBid(@RequestParam Long bid){
        return new ResEntity(0,"success",super.service.showDirectorForBid(bid));
    }

    @GetMapping("/showByBid/{bid}")
    @ApiOperation(value = "根据id查所有信息")
    public ResEntity showByBid(@PathVariable("bid")Long bid){
        return new ResEntity(0,"success",super.service.showByBid(bid));
    }

    @GetMapping("/showByName")
    @ApiOperation(value = "模糊")
    public ResEntity showByName(@RequestParam Long bid,@RequestParam int page,@RequestParam int limit){
        Page<BusInfo> p = new Page<>(page,limit);
        p.setRecords(super.service.pageInfoByName(p,bid));
        return new ResPageEntity(p);
    }

    @GetMapping("/showSimple")
    @ApiOperation(value = "简单展示")
    public ResEntity showSimple(@RequestParam int page,@RequestParam int limit){
        Page<BusInfo> p = new Page<>(page,limit);
        p.setRecords(super.service.showSimple(p));
        return new ResPageEntity(p);
    }


    @GetMapping("/showAllDName")
    @ApiOperation(value = "显示负责人姓名")
    public ResEntity showAllDName(){
        return new ResEntity(0,"success",super.service.showAllDName());
    }

    @PutMapping("/updateTimeByBid")
    public ResEntity updateTimeByBid(@RequestBody BusInfo busInfo){
        super.service.updateTimeByBid(busInfo.getBid());
        return service.updateById(busInfo)?resEntity.OK():resEntity.Failure("操作失败，请重试!");
    }

}
